package com.atguigu.headline.dao.impl;

import com.atguigu.headline.dao.BaseDao;
import com.atguigu.headline.dao.NewsUserDao;
import com.atguigu.headline.pojo.NewsUser;

import java.util.List;

public class NewsUserDaoImpl extends BaseDao implements NewsUserDao{
    BaseDao baseDao=new BaseDao();

    @Override
    public NewsUser finduser(String username) {
        String sql="select uid,username,user_pwd userPwd ,nick_name nickName from news_user where username = ?";
        List<NewsUser> list = baseDao.baseQuery(NewsUser.class, sql, username);
        return list.size()>0 && list!=null?list.get(0):null;
    }

    @Override
    public NewsUser getUserInfo(int i) {
        String sql="select uid,username,user_pwd userPwd ,nick_name nickName from news_user where uid = ?";
        List<NewsUser> list = baseDao.baseQuery(NewsUser.class, sql, i);
        return list.size()>0 && list!=null?list.get(0):null;
    }


    @Override
    public int registerUser(NewsUser newsUser) {
        String sql ="insert into news_user values(DEFAULT,?,?,?)";
        return baseUpdate(sql,newsUser.getUsername(),newsUser.getUserPwd(),newsUser.getNickName());
    }
}
